package com.trsvax.tapestry.instrumentation.pages.thread;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.trsvax.tapestry.instrumentation.ThreadDetail;
import com.trsvax.tapestry.instrumentation.services.TapestryAppender;

public class ThreadIndex {

	@Inject
	private TapestryAppender tapestryAppender;

	@Property
	private ThreadDetail detail;

	@Property
	private ThreadDetail log;

	@Log
	void onActivate(Integer threadID) {
		detail = tapestryAppender.getDetail(threadID);
	}

	public boolean getHasDetail() {
		return detail == null;
	}

	public Integer onPassivate() {
		if (detail == null)
			return null;
		return detail.getThreadID();
	}

	public ThreadDetail[] getLogs() {
		return tapestryAppender.getLogs();
	}

	public List<String> getLoggerNames() {
		List<String> names = new ArrayList<String>();
		names.add("Page");
		names.add("com.trsvax");
		// names.add("org.apache");
		// names.add("tapestry");
		return names;
	}

}
